import Vue from 'vue'
import VueRouter from 'vue-router'
import home from '../views/homepageView.vue'

Vue.use(VueRouter)

const routes = [{
    path: '/',
    redirect: '/home'
  },
  {
    path: '/home',
    name: 'home',
    component: home
  },
  {
    path: '/search',
    name: 'search',
    component: () => import('../views/searchView.vue')
  },
  {
    path: '/details',
    name: 'details',
    component: () => import('../views/detailsView.vue')
  },
  {
    path: '/info',
    name: 'info',
    component: () => import('../views/infoView.vue')
  },
  {
    path: '/follow',
    name: 'follow',
    component: () => import('../views/followView.vue')
  },
  {
    path: '/infodetails',
    name: 'infodetails',
    component: () => import('../views/infoDetails.vue')
  },
  {
    path: '/infodetailstwo',
    name: 'infodetailstwo',
    component: () => import('../views/infodetailsTwo.vue')
  },
  {
    path: '/recharge',
    name: 'recharge',
    component: () => import('../views/recharge_View.vue')
  },
  {
    path:'/recharge_Alipay',
    name:"recharge_Alipay",
    component: () => import("../views/recharge_AlipayView.vue")
  },
  {
    path:'/personal_info',
    name:"personal_info",
    component: () => import("../views/personal_infoView.vue")
  },
  {
    path:'/chat',
    name:"chat",
    component: () => import("../views/chatView.vue")
  },
  {
    path:'/feedback',
    name:"feedback",
    component: () => import("../views/feedbackView.vue")
  },
  {
    path:'/privacy',
    name:"privacy",
    component: () => import("../views/privacyView.vue")
  },
  {
    path:'/binding',
    name:"binding",
    component: () => import("../views/bindingView.vue")
  },
  {
    path:'/news',
    name:"news",
    component: () => import("../views/newsView.vue")
  },
  {
    path:'/fans',
    name:"fans",
    component: () => import("../views/fansView.vue")
  },
  {
    path: '/user',
    name: 'user',
    component: () => import('../views/userinfoView.vue'),
    beforeEnter: (to, from, next) => {
      let token = window.localStorage.getItem("token");
      if (!token) {
        next("/login");
        return;
      } else {
        next();
      }
    }
  },
  {
    path: '/login',
    name: 'login',
    component: () => import('../views/loginView.vue')
  }
]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes,
  scrollBehavior() {
    return {
      x: 0,
      y: 0
    }
  }
})


export default router